// 电影服务 - 连接后端电影API
import apiService from './apiService';

export const movieService = {
  // 获取电影列表
  async getMovies(params = {}) {
    const result = await apiService.movie.getMovies(params);
    if (result.success) {
      return result.data;
    }
    throw new Error(result.error || '获取电影列表失败');
  },

  // 获取单个电影详情
  async getMovie(id) {
    const result = await apiService.movie.getMovie(id);
    if (result.success) {
      return result.data;
    }
    throw new Error(result.error || '获取电影详情失败');
  },

  // 搜索电影
  async searchMovies(query) {
    const result = await apiService.movie.searchMovies(query);
    if (result.success) {
      return result.data;
    }
    throw new Error(result.error || '搜索电影失败');
  },

  // 获取分类列表
  async getCategories() {
    const result = await apiService.movie.getCategories();
    if (result.success) {
      return result.data;
    }
    throw new Error(result.error || '获取分类列表失败');
  },

  // 获取分类下的电影
  async getMoviesByCategory(categoryId) {
    const result = await apiService.movie.getMoviesByCategory(categoryId);
    if (result.success) {
      return result.data;
    }
    throw new Error(result.error || '获取分类电影失败');
  },

  // 获取热门电影
  async getPopularMovies() {
    const result = await apiService.movie.getMovies({ sort: 'popular', limit: 10 });
    if (result.success) {
      return result.data;
    }
    throw new Error(result.error || '获取热门电影失败');
  },

  // 获取最新电影
  async getLatestMovies() {
    const result = await apiService.movie.getMovies({ sort: 'latest', limit: 10 });
    if (result.success) {
      return result.data;
    }
    throw new Error(result.error || '获取最新电影失败');
  },

  // 获取指定类型的分类列表
  async getActiveCategoriesByType(type) {
    const result = await apiService.movie.getActiveCategoriesByType(type);
    if (result.success) {
      return result.data;
    }
    throw new Error(result.error || '获取分类列表失败');
  }
};

export default movieService;